<?php
namespace app\index\controller;

use think\Db;


class Index
{
    public function index()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改（2006-2018） - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }

    public function hello($name = 'ThinkPHP5')
    {
        return 'hello,' . $name;
    }

    public function api()
    {
        // return 'hello,api';
        // $event = controller('Blog','event');
        // $event = new \app\index\event\Blog();
        // echo $event->update(12156);
        // $user = new \app\index\user\Login();
        // $user = controller('Login','user');
        // echo $user->index();
        $user = action('Login\index',[],'user');
        return $user;
    }

    public function kapi()
    {
        // return 'hello,kapi';
        // $res = Db::table('v_tb_material ')->select();
        // dump($res);

        $json = file_get_contents('php://input');
        $data = json_decode($json,true);

        $validate = new \app\index\validate\Kapi;
        if (!$validate->check($data)) {
            return ret_json('',[],-1,$validate->getError());
        }

        $action = '';
        switch($data['command']){
            case "get_material":
                $action = action('Material/get_material',[$data],'controller');
                break;
            case "update_material":
                $action = action('Material/update_material',[$data],'controller');
                break;
            case "get_unit":
                $action = action('Unit/get_unit',[$data],'controller');
                break;
            case 'test':
                $action = action('Blog/update',['id'=>5],'event');
                break;
            case "get_supplier":
                $action = action('Supplier/getSupplier',[$data],'api');
                break;
            default:
                $action = action('Miss/get_data',[$data],'controller');
        }

        return $action;
    }

    public function php_info()
    {
        phpinfo();
    }
}
